<template>
  <div class="management-merchant views-container">
    <div class="wlm-table">
      <div class="wlm-dialog-content">
        <!-- :ref="formFormatData.key"
          :model="formFormatData.formData" -->
        <el-form
        :ref="formFormatData.key"
          :model="formFormatData.formData"
          size="small"
          label-width="150px"
          class="retail-form"
          label-position="right"
          style="width:50%"
        >
               <el-form-item label="域名">
                    <el-input v-model.trim="formFormatData.formData.url" :disabled="$route.query.url_id"></el-input>
                  </el-form-item>
           <el-form-item label="选择平台">
                    <ChoosePlat :response="responseFunction" v-if="!!!formFormatData.formData.wxapp_id"></ChoosePlat>
                    <div v-if="!!formFormatData.formData.wxapp_id">
                      <el-tag closable @close="closeTag">
                      {{formFormatData.formData.name}}
                    </el-tag>
                    </div>

                  </el-form-item>
            <el-form-item label="域名版权">
                            <el-radio-group v-model="formFormatData.formData.copyright_open">
                              <el-radio :label="1">开启</el-radio>
                              <el-radio :label="2">关闭</el-radio>
                            </el-radio-group>
                  </el-form-item>
          <el-form-item label="域名内容">
                          <ueditor
                                :ueditorChange="shopInfoChange"
                                :ueditorList="ueditorList"
                                :bindIndex="1"
                                :defaultMsg='defaultMsg1'
                                :config='{initialFrameWidth: null,initialFrameHeight: 350}'
                                ref="by_know"></ueditor>
                  </el-form-item>
        </el-form>
      </div>
    </div>
     <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
        <el-button size="small" @click="saveDialogSubmit" type="primary" :loading="butt">保存</el-button>
        <!-- <router-link tag="span" to="/setting/falseUrl">
            <el-button size="small">返回</el-button>
        </router-link> -->
    </div>
  </div>
</template>
<script>
import { urlAddEdit,urlDetail } from '@/api/platform'
import ueditor from '@/components/Ueditor/index'
import ChoosePlat from '@/components/platform/index'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  components: {
    ueditor,
    ChoosePlat
  },
  created () {
     this.$nextTick(() => {
    if(this.$route.query.url_id){
       this.urlDetailbtn()
    }
    })
  },
  data() {
    return {
      butt:false,
        ueditorList: [],
       defaultMsg1: '',
      formFormatData: {
        key: 'user',
        model: {
          noCreateEdit: false,
          hasMessage: false,
          closeDialog: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
             api: urlDetail, 
            params: {
              url_id: this.$route.query.url_id
            },
             redirect: 'url_id'
          },
        //   submitForm: urlAddEdit,
        },
        formData: {
          url: '',
          wxapp_id: 0,
          name: '',
          url_id:'',
          copyright_open: 2,
          copyright: '',
        }
      },
    }
  },
  methods: {
    formFormatCallBack(data, type, response) {
                if (type === 'editForm') {
                    const { content } = data
                    this.defaultMsg1 = content
                }
            },
    urlDetailbtn(){
      urlDetail({url_id:this.$route.query.url_id}).then(res=>{
         if(res.data.code==1){
              this.formFormatData.formData.copyright = res.data.data.copyright
              this.defaultMsg1 = res.data.data.copyright
              this.formFormatData.formData.copyright_open = res.data.data.copyright_open
              this.formFormatData.formData.url = res.data.data.url
              this.formFormatData.formData.url_id = res.data.data.url_id
              this.formFormatData.formData.name =  res.data.data.name
              this.formFormatData.formData.wxapp_id = res.data.data.wxapp_id
          }
      })
    },
    // 保存添加
    saveDialogSubmit() {
      // this.formFormatSubmit()
       this.formFormatData.formData.copyright = this.defaultMsg1
        this.butt=true
      urlAddEdit(this.formFormatData.formData).then(response => {
        if (!!response.data && response.data.code == 1) {
          this.butt=false
          this.$message.success('保存成功')
          this.$router.push('/setting/falseUrl')
          this.getTableList()
        } else {
          this.butt = false
          this.$message.error('保存失败')
        }
      }).finally(()=>{
        this.butt = false
      })
    },
     shopInfoChange(msg) {
            this.defaultMsg1 = msg
            console.log("fdsfdsfdsfd++++++++++",msg)
            },
     responseFunction(row) {
      this.formFormatData.formData.name = row.name
      this.formFormatData.formData.wxapp_id = row.wxapp_id

      console.log('子组件回调', row)
    },
    // 关闭标签时将标签类容清空
    closeTag() {
      this.formFormatData.formData.name = ''
      this.formFormatData.formData.wxapp_id = 0
    },
  }
}
</script>